//
// Created by lfm on 2025/3/27.
//

#include "Time.h"
#include <iostream>

Time::Time(int h, int m, int s) {
    hour = h;
    minute = m;
    second = s;
}

void Time::print_time() {
    std::cout << hour << ":" << minute << ":" << second << std::endl;
}

void Time::update1() {
    second++;
    if (second >= 60) {
        second = 0;
        minute++;
    }
    if (minute >= 60) {
        minute = 0;
        hour++;
    }
    if (hour >= 24) {
        hour = 0;
    }
}

Time Time::operator+(int t) {
    Time result = *this;
    for (int i = 0; i < t; i++) {
        result.update1();
    }
    return result;
}

void Time::update_minus1() {
    second--;
    if (second < 0) {
        second += 60;
        minute--;
    }
    if (minute < 0) {
        minute += 60;
        hour--;
    }
    if (hour < 0) {
        hour += 24;
    }
}

Time Time::operator-(int t) {
    Time result = *this;
    for (int i = 0; i < t; i++) {
        result.update_minus1();
    }
    return result;
}